<template>
  <!--编辑-->
  <el-dialog title="编辑" :visible.sync="dialogFormVisible" width="650px" @open="open">
    <el-form ref="editFormRef" :rules="rules" :model="editFormData" label-width="20%">
      <#list columnList as column>
      <el-form-item label="${column.columnComment}" prop="${column.javaColumnName}">
        <el-input v-model="editFormData.${column.javaColumnName}" placeholder="请输入${column.columnComment}"/>
      </el-form-item>
      </#list>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">
        取消
      </el-button>
      <el-button type="primary" @click="submitForm">
        提交
      </el-button>
    </div>
  </el-dialog>
</template>
<script>
// 接口
import dic from '@/mixins/dic'
import { ${modulePathCamel}Update } from '@/sdk/modules/${modulePath}'

export default {
  name: '${modulePathCamel?cap_first}UpdateForm',
  props: ['rowData'], // 接收父组件的传值
  mixins: [dic],
  watch: {},
  data() {
    return {
      editFormData: {
        name: undefined,
        mobile: undefined,
        email: undefined,
        useFlag: undefined,
        roleIds: []
      },
      roleOptions: [],
      dialogFormVisible: false,
      rules: {
        <#list columnList as column>
        <#if column.columnKey !="PRI">
        ${column.javaColumnName}: [
          { required: true, message: '请输入${column.columnComment}', trigger: 'blur' }
        ],
        </#if>
        </#list>
      }
    }
  },
  created() {
    // this.dic(['use_flag'])
  },
  methods: {
    open() {
      this.editFormData = JSON.parse(JSON.stringify(this.rowData))
      this.editFormData.useFlag = this.editFormData.useFlag.toString()
    },
    submitForm() {
      this.$refs['editFormRef'].validate((valid) => {
        if (valid) {
          ${modulePathCamel}Update(this.editFormData).then(res => {
            if (res.code === 'SUCCESS') {
              this.$message.success('修改成功')
              this.$emit('loadData')
              this.dialogFormVisible = false
            } else {
              this.$message.error(res.failMsg)
            }
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>
